﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Fadd.Logging;
using Fadd.Logging.Filters;
using Fadd.Logging.Targets;
using Xunit;

namespace Fadd.Test.Logging
{
    public class TextLoggerTest
    {
        [Fact]
        public void TestLogging()
        {
            var config = new FileConfiguration
                             {
                                 CreateDateFolder = true,
                                 DaysToKeep = 3,
                                 Path = @"d:\logfiles"
                             };

            FileTarget target =new FileTarget("Everything", config);

            target.Enqueue(new LogEntry
                               {
                                   CreatedAt = DateTime.Now,
                                   LogLevel = LogLevel.Debug,
                                   Message = "Hello world",
                                   StackFrames = new StackTrace().GetFrames(),
                                   ThreadId = Thread.CurrentThread.ManagedThreadId,
                                   UserName = Thread.CurrentPrincipal.Identity.Name
                                   ?? Environment.UserName
                               });

            PaddedFileTarget target2 = new PaddedFileTarget("EVeryone", config);
            target2.Enqueue(new LogEntry
            {
                CreatedAt = DateTime.Now,
                LogLevel = LogLevel.Debug,
                Message = "Hello world",
                StackFrames = new StackTrace().GetFrames(),
                ThreadId = Thread.CurrentThread.ManagedThreadId,
                UserName = Thread.CurrentPrincipal.Identity.Name
                ?? Environment.UserName
            });

            Logger logger = new Logger(new List<ILogFilter>(), new[]{target2, target});
            logger.Info("Hello");
            logger.Debug("Hello");
            logger.Warning("Hello");
            logger.Error("Hello");
        }
    }
}
